Skip to content

DEV-1275: report a Shimmer ready only once its connect sequence has ended - #132

Merged
JongChern merged 1 commit into
masterfrom
DEV-1275_android_ready_after_connect_sequence
Oct 24, 2026
Merged

JongChern merged 1 commit into
masterfrom
DEV-1275_android_ready_after_connect_sequence

Conversation

@JongChern

Copy link
Copy Markdown
Contributor

DEV-1275, ported from the Java driver's fix (ShimmerResearch/Shimmer-Java-Android-API#333). Shimmer overrides the status handler, so the driver's fix doesn't reach Android.

The bug

The connect sequence reads the unit's status part way through, before the battery, the BT firmware version, the calibration dump and the inquiry. On that reply, logAndStreamStatusChanged() moved the state from CONNECTING to CONNECTED, or to SDLOGGING for a unit that is logging, which also sets mIsInitialised. ShimmerBluetoothManagerAndroid and apps take either state as ready, so whatever the app did next went out in among the rest of the sequence. In the Java driver, a configure sent then cut a Shimmer3's calibration dump short and left its accel NaN.

The fix

The sequence's own end, inquiryDone() then isReadyForStreaming(), already moves CONNECTING to CONNECTED or SDLOGGING and sends NOTIFICATION_SHIMMER_FULLY_INITIALIZED. A status reply now leaves CONNECTING to it. Once connected, a status reply still moves the state as before. Unlike ShimmerPC, Shimmer also holds back SDLOGGING, because here it marks the unit initialised.

Tested

  • AAPI_00004_ConnectReadyAfterConnectSequenceTest hands a status reply to the parser while CONNECTING, as the IO thread does. Without the fix, the idle and the logging cases fail.
  • Android HIL on a Shimmer3 (3E36, Classic, from a phone), with the connectReady scenario from the HIL scenarios PR:
    • without this fix: ready reported 1.0-1.2 s before the end of connecting, with 4-5 commands still queued;
    • with it: 8 of 9 connects ready within 0-5 ms of the end. The ninth, a connect to a logging unit, stalled; that looks like the DEV-1266 lock-order deadlock, fixed in driver 0.11.11_beta, which Android isn't pinned to yet.

🤖 Generated with Claude Code

The connect sequence reads the unit's status part way through, before the
battery, the BT firmware version, the calibration dump and the inquiry. On
that reply, logAndStreamStatusChanged() moved the state from CONNECTING to
CONNECTED, or to SDLOGGING for a unit that is logging, which also sets
mIsInitialised. ShimmerBluetoothManagerAndroid and apps take either state as
ready, so whatever the app did next went out in among the rest of the
sequence. The Java HIL found the same defect in the driver's ShimmerPC: a
configure sent then cut a Shimmer3's calibration dump short and left its
accel NaN.

The sequence's own end, inquiryDone() and then isReadyForStreaming(), already
moves CONNECTING to CONNECTED or SDLOGGING and sends
NOTIFICATION_SHIMMER_FULLY_INITIALIZED. A status reply now leaves CONNECTING
to it. Once connected, a status reply still moves the state as before.

This is the driver's DEV-1275 fix, ported: Shimmer overrides the status
handler, so the driver's fix doesn't reach it. Unlike ShimmerPC, Shimmer also
holds back SDLOGGING, because here it marks the unit initialised.

AAPI_00004 hands a status reply to the driver's parser while CONNECTING, as
the IO thread does while not streaming. Without the fix, the idle and the
logging cases fail: the state moves to CONNECTED or SDLOGGING before the
sequence ends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JongChern

Copy link
Copy Markdown
Contributor Author

Retested with driver 0.11.11_beta: the idle connect is fixed; the logging connect is not tested yet

connectReady on s3-3e36 (Shimmer3, LogAndStream v1.1.7) over Classic, from an M2101K6G phone on Android 11, with a 1-byte link CRC. Both builds also had #122, #133, #134, #135 and #136.

Build Idle connect: reported ready this long before the connect sequence ended
without this PR 1178 ms, then 1156 ms: fails, limit 250 ms
with this PR 0 ms, then 0 ms: passes

Not tested yet: the connect to a unit that is logging. 3E36 was docked to charge, and a docked Shimmer3 acknowledges START_LOGGING but doesn't log (status IsDocked = true, IsSDLogging = false). I'll test that part undocked.

Also found: Shimmer3BLEAndroid has the same defect over BLE. On a Shimmer3R it was reported ready 2.7 s early, with driver 0.11.11_beta, and this PR doesn't cover it. I'm fixing that separately.

🤖 Generated with Claude Code

@JongChern

Copy link
Copy Markdown
Contributor Author

Verified on a second Shimmer3, including the connect to a logging unit (24 Oct)

connectReady on s3-be69 (Shimmer3, LogAndStream v1.1.7) over Classic, undocked so it logs. Current master (driver 0.11.11_beta), 1-byte link CRC, from an M2101K6G phone on Android 11.

Build Idle connect: reported ready this early Connect while logging: reported ready this early
master 1200 ms, then 1231 ms: fails 1250 ms, then 1273 ms: fails
master + this PR 1 ms, then 2 ms: passes 0 ms, then 1 ms: passes, and the connect ends in SD Logging

So the fix is now confirmed on two Shimmer3s (3E36 and BE69), for both idle and logging connects.

🤖 Generated with Claude Code

@JongChern
JongChern merged commit 061dd36 into master Oct 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant